package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.CallNoteMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeCallNote implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        //*WT,866248050395985,CALLNOTE,092808,18797874506,1,0,V,0.0000,S,0.0000,W,0.00,0,040621,FFDFFFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei=split[1];
        String commandNumber=split[3];
        String callNum=split[4];//来去电号码
        String callType=split[5];//来去电类型 0-来电 1-去电
        String callTime=split[6];//通话时长
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];//日月年
        String deviceStatus = split[15];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        CallNoteMessage mqCallNoteMessage = new CallNoteMessage();
        mqCallNoteMessage.setCallType(Integer.parseInt(callType));
        mqCallNoteMessage.setCommandNumber(commandNumber);
        mqCallNoteMessage.setDeviceDate(date);
        mqCallNoteMessage.setImei(imei);
        mqCallNoteMessage.setDeviceTime(commandNumber);
        mqCallNoteMessage.setPhone(callNum);
        mqCallNoteMessage.setDuration(callTime);
        mqCallNoteMessage.setDeviceStatus(deviceStatus);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqCallNoteMessage.setMqLocationData(mqLocationData);
        String res="*WT,".concat(imei).concat(",CALLNOTE,").concat(commandNumber).concat(",CALLNOTE_GET#");
        return structureMessage(Constants.UPLOAD,Constants.UP_CALL_NOTE,true,res,mqCallNoteMessage);
    }
}
